//未解决问题：会多打印wrong
function Account(balance, password) {
  this.balance = balance;
  this.password = password;
}
Account.prototype.dispatch = function (method, amount, input) {
  const output = x => console.log(x); //统一用output输出
  let i = 0;
  const self = this;
  if (method === 'withdraw') {
    if (i === 6) return output('call the cops');
    if (input === this.password) {
      i = 0;
      return withdraw(amount);
    }
    i += 1;
    return output('wrong');
  }
  if (method === 'deposit') return deposit(amount);
  return output('no such method');

  function withdraw(amount) {
    if (self.balance >= amount) {
      self.balance -= amount;
      return output(self.balance);
    }
    return output('not enough money');
  }
  function deposit(amount) {
    self.balance += amount;
    return output(self.balance);
  }
};

const acc = new Account(100, '123456');
// acc.dispatch('withdraw', 100, '12345');
acc.dispatch('withdraw', 99, '123456');
// acc.dispatch('deposit', 200);
// acc.dispatch('abc', 200);
